package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.RedPacketBean;
import com.joplus.housekeeper.utils.DecimalFormatTool;
import com.joplus.housekeeper.utils.StringUtils;

import java.util.List;

/**
 * Created by ccm on 2016/12/27 13:08
 */
public class RedOrderAdatper extends BaseAdapter {
    private Context mContext;
    private List<RedPacketBean.DataBean.CouponListBean> list;

    public RedOrderAdatper(Context context, List<RedPacketBean.DataBean.CouponListBean> list) {
        mContext = context;
        this.list = list;


    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_redpacket, null);
            holder = new Holder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        if ("use".equals(list.get(position).getCouponCategory())) {
            if (StringUtils.isEmpty(list.get(position).getArea())) {
                StringUtils.setText(holder.tv_way, "满" + DecimalFormatTool.getPaidMoneyString(list.get(position).getConditionMoney() + "") + "可用" );
            }else{
                StringUtils.setText(holder.tv_way, "满" + DecimalFormatTool.getPaidMoneyString(list.get(position).getConditionMoney() + "") + "可用" + "," + list.get(position).getArea());
            }

            StringUtils.setText(holder.tv_money, "￥" + DecimalFormatTool.getPaidMoneyString(list.get(position).getCouponMoney() + ""));
        } else {
            if (StringUtils.isEmpty(list.get(position).getArea())) {
                StringUtils.setText(holder.tv_way, list.get(position).getTagTwo() );
            }else{
                StringUtils.setText(holder.tv_way, list.get(position).getTagTwo() + "," + list.get(position).getArea());
            }

            StringUtils.setText(holder.tv_money, "￥" + list.get(position).getValue());
            StringUtils.setText(holder.tv_top, list.get(position).getTagOne());
        }
        StringUtils.setText(holder.tv_title, list.get(position).getCouponName());
        String expirDate = list.get(position).getExpirDate();
        StringUtils.setText(holder.tv_time, "截止时间:" + expirDate);
        return convertView;
    }

    public static class Holder {
        TextView tv_title;
        TextView tv_way;
        TextView tv_time;
        TextView tv_money;
        TextView tv_top;

        public Holder(View view) {
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_way = (TextView) view.findViewById(R.id.tv_way);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
            tv_money = (TextView) view.findViewById(R.id.tv_money);
            tv_top = (TextView) view.findViewById(R.id.tv_top);
        }
    }

}
